package com.rinlink.jbcodec.creator;

import com.alibaba.fastjson.JSONObject;
import com.rinlink.jbcodec.BytesToObjectCreatorMap;
import com.rinlink.jbcodec.JSONCodec;
import com.rinlink.jbcodec.common.CreatorUtils;
import com.rinlink.jbcodec.transform.BytesToJSONList;
import com.rinlink.jbcodec.transform.Transform;

import java.nio.ByteBuffer;

public  class ByteBufferToJSONListCreator extends ByteBufferToObjectCreator {

    private BytesToObjectCreatorMap creatorMap;

    public ByteBufferToJSONListCreator(BytesToObjectCreatorMap creatorMap){
        this.creatorMap = creatorMap;
    }

    @Override
    protected Transform create(JSONObject attr, ByteBuffer data, JSONObject t) {
        JSONCodec.Scheme scheme = CreatorUtils.getScheme(attr);
        int arraySize = CreatorUtils.getListSize(attr,t);
        return new BytesToJSONList(data,arraySize,scheme,creatorMap);
    }
}
